package com.sky.controller.user;

import com.sky.dto.ShoppingCartDTO;
import com.sky.result.Result;
import com.sky.service.ShoppingCartService;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/user/shoppingCart")
@Slf4j
public class ShoppingCartController {
	
	private final ShoppingCartService shoppingCartService;
	
	public ShoppingCartController(ShoppingCartService shoppingCartService) {this.shoppingCartService = shoppingCartService;}
	
	@PostMapping("/add")
	@ApiOperation("添加购物车")
	public Result<String> add(@RequestBody ShoppingCartDTO shoppingCartDTO) {
		log.info("添加购物车：{}", shoppingCartDTO);
		shoppingCartService.addShoppingCart(shoppingCartDTO);
		return Result.success();
	}
	
	@GetMapping("/list")
	public Result getByUserId() {
		return shoppingCartService.getByUserId();
	}
	
	@PostMapping("/sub")
	public Result deleteByDishOrSetmealById(@RequestBody ShoppingCartDTO shoppingCartDTO) {
		return shoppingCartService.deleteByDishOrSetmealById(shoppingCartDTO);
	}
	
	@DeleteMapping("/clean")
	public Result clean() {
		return shoppingCartService.clean();
	}
}
